﻿<navigation:Page 
    x:Class="AppShare.Home" 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:navigation="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Navigation"
    xmlns:sdk="http://schemas.microsoft.com/winfx/2006/xaml/presentation/sdk"
    xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" 
    mc:Ignorable="d" d:DesignWidth="640" d:DesignHeight="480"  
    Style="{StaticResource PageStyle}" 
    >

    <sdk:Page.Resources>
        <SolidColorBrush x:Key="DetailsBrush" Color="Gray"></SolidColorBrush>
    </sdk:Page.Resources>

    <Grid x:Name="LayoutRoot">
        <ScrollViewer x:Name="PageScrollViewer" Style="{StaticResource PageScrollViewerStyle}" >

            <StackPanel x:Name="ContentStackPanel" Style="{StaticResource ContentStackPanelStyle}">

                <TextBlock Style="{StaticResource HeaderTextStyle}" 
                           Text="{Binding Path=ApplicationStrings.HomePageTitle, Source={StaticResource ResourceWrapper}}"/>
                <TextBlock Style="{StaticResource ContentTextStyle}" 
                           Text="搜索并下载MSDN原版文件.."/>
                <TextBlock Style="{StaticResource ContentTextStyle}" 
                           Text="{Binding}" Loaded="ContentText_Loaded" />

                <toolkit:BusyIndicator BusyContent="{Binding Path=ApplicationStrings.BusyIndicatorMessage, Source={StaticResource ResourceWrapper}}"
                             IsBusy="{Binding IsWorking}" Loaded="BusyIndicator_Loaded" >
                    <Grid Margin="30,15,30,15">
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="235" />
                            <ColumnDefinition />
                        </Grid.ColumnDefinitions>

                        <toolkit:Accordion Grid.Column="0" HorizontalAlignment="Stretch" VerticalAlignment="Top"
                                       SelectionMode="ZeroOrOne" FontFamily="Verdana, Microsoft YaHei, SimSun"
                                       BorderBrush="DarkGray" BorderThickness="1"
                                       SelectionSequence="CollapseBeforeExpand"
                                       ItemsSource="{Binding}" Loaded="Accordion_Loaded" SelectionChanged="Accordion_SelectionChanged">
                            <!--Begin binding-->
                            <toolkit:Accordion.ItemTemplate>
                                <DataTemplate>
                                    <StackPanel Orientation="Horizontal">
                                        <TextBlock FontSize="11" Text="{Binding Path=ProductName}"/>
                                        <TextBlock FontSize="11" Text="{Binding Path=ProductCount, StringFormat=' - (\{0\})'}"/>
                                    </StackPanel>
                                </DataTemplate>
                            </toolkit:Accordion.ItemTemplate>
                            <toolkit:Accordion.ContentTemplate>
                                <DataTemplate>
                                    <ListBox FontSize="9" BorderThickness="0" 
                                             Background="Transparent"                     
                                             SelectionChanged="ListBox_SelectionChanged"
                                             ItemsSource="{Binding Path=Families}">
                                        <ListBox.ItemTemplate>
                                            <DataTemplate>
                                                <StackPanel Margin="16,0,0,0" 
                                                            Orientation="Horizontal" HorizontalAlignment="Stretch">
                                                    <TextBlock Text="*" Foreground="DarkBlue" Margin="0,0,0,2" />
                                                    <TextBlock Text="{Binding Path=FamilyName}" Foreground="DarkBlue" />
                                                </StackPanel>
                                            </DataTemplate>
                                        </ListBox.ItemTemplate>
                                    </ListBox>
                                </DataTemplate>
                            </toolkit:Accordion.ContentTemplate>
                            <!--End binding-->
                        </toolkit:Accordion>


                        <StackPanel Grid.Column="1" Margin="8,0,0,0" x:Name="dataPanel">
                            <Border BorderBrush="DarkGray" BorderThickness="1">
                                <sdk:DataGrid Margin="1"  HorizontalAlignment="Stretch" VerticalAlignment="Top"
                                      AutoGenerateColumns="False"
                                      AlternatingRowBackground="AliceBlue" 
                                      Background="DarkKhaki"
                                      IsReadOnly="True" FontFamily="Verdana, Microsoft YaHei, SimSun"
                                      ItemsSource="{Binding}">
                                    <sdk:DataGrid.RowDetailsTemplate>
                                        <DataTemplate>
                                            <Border Background="LightYellow" MouseRightButtonDown="Details_MouseRightButtonDown">
                                                <StackPanel Margin="8,2,2,2">
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="File Name: " FontWeight="Bold" Foreground="{StaticResource DetailsBrush}" />
                                                        <TextBlock Text="{Binding Path=FileName}" Foreground="{StaticResource DetailsBrush}" />
                                                    </StackPanel>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="Date Published (UTC): " FontWeight="Bold" Foreground="{StaticResource DetailsBrush}" />
                                                        <TextBlock Text="{Binding Path=PublishDate}" Foreground="{StaticResource DetailsBrush}" />
                                                    </StackPanel>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="ISO/CRC: " FontWeight="Bold" Foreground="{StaticResource DetailsBrush}" />
                                                        <TextBlock Text="{Binding Path=CRC}" Foreground="{StaticResource DetailsBrush}" />
                                                    </StackPanel>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="SHA1: " FontWeight="Bold" Foreground="{StaticResource DetailsBrush}" />
                                                        <TextBlock Text="{Binding Path=SHA1}" Foreground="{StaticResource DetailsBrush}" />
                                                    </StackPanel>
                                                    <StackPanel Orientation="Horizontal">
                                                        <TextBlock Text="File Size: " FontWeight="Bold" Foreground="{StaticResource DetailsBrush}" />
                                                        <TextBlock Text="{Binding Path=FileSize}" Foreground="{StaticResource DetailsBrush}" />
                                                    </StackPanel>
                                                </StackPanel>
                                            </Border>
                                        </DataTemplate>
                                    </sdk:DataGrid.RowDetailsTemplate>
                                    <sdk:DataGrid.Columns>
                                        <sdk:DataGridTextColumn Header="产品名称" Binding="{Binding ShipName}" MinWidth="400" MaxWidth="550" />
                                        <sdk:DataGridTextColumn Header="更新时间" Binding="{Binding Path=LastUpdated, StringFormat=\{0:d\}}" MinWidth="110" />
                                        <sdk:DataGridTemplateColumn Header="操作" SortMemberPath="IsAvailable" MinWidth="110">
                                            <sdk:DataGridTemplateColumn.CellTemplate>
                                                <DataTemplate>
                                                    <StackPanel Orientation="Horizontal">
                                                        <HyperlinkButton Content="复制" Click="HyperlinkButton_Click" IsEnabled="{Binding Path=IsAvailable}" />
                                                        <HyperlinkButton Content="下载" NavigateUri="{Binding Path=ED2K}" TargetName="_blank" IsEnabled="{Binding Path=IsAvailable}" />
                                                    </StackPanel>
                                                </DataTemplate>
                                            </sdk:DataGridTemplateColumn.CellTemplate>
                                        </sdk:DataGridTemplateColumn>
                                    </sdk:DataGrid.Columns>
                                </sdk:DataGrid>
                            </Border>
                            <Border Margin="1" />
                            <sdk:DataPager Source="{Binding}" PageSize="12" />
                        </StackPanel>
                    </Grid>
                </toolkit:BusyIndicator>
            </StackPanel>

        </ScrollViewer>
    </Grid>

</navigation:Page>